package com.pda.gongpin.presenter;


import com.pda.gongpin.bean.FullTrayInDetailBean;
import com.pda.gongpin.bean.request.EntryNoRequest;
import com.pda.gongpin.contract.FullTrayInDetailContract;
import com.pda.gongpin.net.NetUtils;
import com.wangshen.base.net.bean.BaseAppEntity;
import com.wangshen.base.ui.mvp.base.presenter.BasePresenter;

import java.util.List;

import io.reactivex.functions.Consumer;

public class FullTrayInDetailPresenter extends BasePresenter<FullTrayInDetailContract.View> implements FullTrayInDetailContract.Presenter {
    @Override
    public void palletEntryDetail(String entryNo) {
        NetUtils.geApi().getDetails(entryNo)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<List<FullTrayInDetailBean>>>() {
                    @Override
                    public void accept(BaseAppEntity<List<FullTrayInDetailBean>> listBaseAppEntity) throws Exception {
                        getView().setList(listBaseAppEntity.getData());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }

    @Override
    public void entryTakenOffShelves(String entryDetailNo) {
        NetUtils.geApi().entryTakenOffShelves(entryDetailNo)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<List<FullTrayInDetailBean>>>() {
                    @Override
                    public void accept(BaseAppEntity<List<FullTrayInDetailBean>> listBaseAppEntity) throws Exception {
                        getView().showMessage(listBaseAppEntity.getMsg());
                        getView().onSuccess();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }

    @Override
    public void deleteEntryNotAvailable(String entryDetailNo) {
        NetUtils.geApi().deleteEntryNotAvailable(entryDetailNo)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<List<FullTrayInDetailBean>>>() {
                    @Override
                    public void accept(BaseAppEntity<List<FullTrayInDetailBean>> listBaseAppEntity) throws Exception {
                        getView().showMessage(listBaseAppEntity.getMsg());
                        getView().onSuccess();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }
}
